home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2820 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  41 lines

  1. Path: dialup-147.austin.io.com!user
  2. From: hamilton@shokwave.com (Jim Hamilton)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q:order of evaluation
  5. Date: Thu, 18 Jan 1996 20:45:57 -0600
  6. Organization: Disorganized
  7. Message-ID: <hamilton-1801962045570001@dialup-147.austin.io.com>
  8. References: <4dfhlu$a33$1@mhafn.production.compuserve.com>
  9. NNTP-Posting-Host: dialup-147.austin.io.com
  10. X-Newsreader: Yet Another NewsWatcher 2.0.5b5
  11.  
  12. In article <4dfhlu$a33$1@mhafn.production.compuserve.com>, Holger Maier
  13. <100336.3326@CompuServe.COM> wrote:
  14.  
  15. >Consider
  16. >#include <iostream>
  17. >int main() {
  18. >  int i=1;int j=i+(i+=1);
  19. >  cout<<i<<','<<j<<'\n';
  20. >  return 0;
  21. >}
  22. >on my compiler this produces 2,4
  23. >Looked up the ARM:
  24. >5: .. The order of evaluation of subexpressions is determined by the
  25. >precedence and grouping of operators.
  26. >5.7: The additive operators + and - group left to right.
  27. >So, j should be assigned 3 ??
  28. >Now the question to you C++ gurus out there on the nets:
  29. >Is it really a compiler bug or is it just me misinterpreting the 
  30. >ARM?
  31. >BTW: I know we should not code like that...
  32. >Holger
  33.  
  34. The highest precedence in any expression is the insides of parentheses
  35. ().  Therefore (i+=1) is evaluated before i+().
  36.  
  37. -- 
  38. JFH
  39.  
  40. [This .sig intentionally left blank.]
  41.